package com.tesis_2.UI;

import java.util.ArrayList;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.layout;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLLocales;
import com.tesis_2.MO.MOLocal;
import com.tesis_2.MO.MORestaurant;
import com.tesis_2.Utils.UTLocalesSimpleAdapter;
import com.tesis_2.Utils.UTRestaurantsSimpleAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class UIAceptarReservaLocal extends ListActivity {

	private Integer nRest;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_uiaceptar_reserva_local);
		Bundle b = getIntent().getExtras();
		nRest = b.getInt("RestId");
		
		ArrayList<MOLocal> lsLocales = new ArrayList<MOLocal>();
		
		try {
			lsLocales = BLLocales.getLocalsByRestId(nRest);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setListAdapter( new UTLocalesSimpleAdapter(this, lsLocales));
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater()
				.inflate(R.menu.activity_uiaceptar_reserva_local, menu);
		return true;
	}
	

	@Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
		Intent intent = new Intent(getApplicationContext(), UIAceptarReserva.class);
		MOLocal lo = (MOLocal) getListAdapter().getItem(position);
		intent.putExtra("RestId", nRest);
		intent.putExtra("LocalId", lo.getId());
		startActivity(intent);
		
    }

}
